home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROCS.ZIP / GETPATHS.ICN < prev    next >
Text File  |  1992-09-28  |  2KB  |  61 lines

  1. ############################################################################
  2. #
  3. #    File:     getpaths.icn
  4. #
  5. #    Subject:  Procedure to generate elements in path environment variable
  6. #
  7. #    Author:   Richard L. Goerwitz
  8. #
  9. #    Date:     June 1, 1991
  10. #
  11. ###########################################################################
  12. #
  13. #    Version:  1.3
  14. #
  15. ###########################################################################
  16. #
  17. #      Suspends, in turn, the paths supplied as args to getpaths(),
  18. #  then all paths in the PATH environment variable.  A typical
  19. #  invocation might look like:
  20. #
  21. #     open(getpaths("/usr/local/lib/icon/procs") || filename)
  22. #
  23. #  Note that getpaths() will be resumed in the above context until
  24. #  open succeeds in finding an existing, readable file.  Getpaths()
  25. #  can take any number of arguments.
  26. #
  27. ############################################################################
  28. #
  29. #  Requires: UNIX or MS-DOS
  30. #
  31. ############################################################################
  32.  
  33. procedure getpaths(base_paths[])
  34.  
  35.     local paths, p
  36.     static sep, trailer, trimmer
  37.     initial {
  38.     if find("UNIX", &features) then {
  39.         sep := ":"
  40.         trailer := "/"
  41.         trimmer := cset(trailer || " ")
  42.         }
  43.     else if find("MS-DOS", &features) then {
  44.         sep := ";"
  45.         trailer := "\\"
  46.         trimmer := cset(trailer || " ")
  47.     }
  48.         else stop("getpaths:  OS not supported.")
  49.     }
  50.  
  51.     suspend !base_paths
  52.     paths := getenv("PATH")
  53.     \paths ? {
  54.     tab(match(sep))
  55.     while p := 1(tab(find(sep)), move(1))
  56.     do suspend ("" ~== trim(p,trimmer)) || trailer
  57.     return ("" ~== trim(tab(0),trimmer)) || trailer
  58.     }
  59.  
  60. end
  61.